import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'package:untitled1/app/res/myColors.dart';
import 'package:untitled1/app/utils/utilRouter.dart';
import 'package:untitled1/app/utils/utilScreen.dart';

import 'package:untitled1/app/widgets/toast/MyToast.dart';


import '../../../widgets/base_page/BaseStatefulPage.dart';
import 'EmployerPageController.dart';
import 'employer_page/MyListView.dart';
import 'employer_page/employer_page_dialog/EmployerPageDialog.dart';
//雇主需求列表
class EmployerPage extends BaseStatefulPage {

  const EmployerPage({super.key}) : super(pageName: "首页");

  @override
  BaseStatefulPageState<BaseStatefulPage> createState() => _GuZhuPageState();
}

class _GuZhuPageState extends BaseStatefulPageState<EmployerPage> {
  String? _error;
  bool _isEmpty = false;
  final EmployerPageController controller = Get.put(EmployerPageController());


  @override
  Widget buildPage(BuildContext context) {
    if (_error != null) {
      return buildErrorView(_error);
    }
    if (_isEmpty) {
      return buildEmptyView();
    }
    return Scaffold(
      body:getBody(),
    );
  }
  Widget getBody(){
    // if (true) {
    //   return buildEmptyView() ;
    // }
   return Obx(() =>Container(
      color: myColors.white,
      width: utilScreen.getScreenWidth(context),
      height: utilScreen.getScreenHeight(context),
      child: Column(
        children: [
          SizedBox(height: 50, width: double.infinity),
          Container(
            height: 50,
            width: double.infinity,
            child: Stack(
              children: [
                Align(
                  alignment: Alignment.centerLeft,
                  child:  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Container(
                        alignment: Alignment(-2, 0),
                        child: TextButton(
                          onPressed: () {
                            controller.page_index.value = 0;
                          },
                          child: (Text("全部", style: getViewSelectTitle(0))),
                        ),
                      ),
                      Container(
                        alignment: Alignment(-2, 0),
                        child: TextButton(
                          onPressed: () {
                            controller.page_index.value = 1;
                          },
                          child: Text("我锁定", style: getViewSelectTitle(1)),
                        ),
                      ),
                    ],
                  ),

                ),
                Align(
                  alignment: Alignment.centerRight,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: [
                      GestureDetector(
                        onTap: () {
                          print('按钮被点击了');
                          // MyToast.show(context,'aaa');
                          EmployerPageDialog.dialog_citySelect(context,(data){

                          });
                        },
                        child:Row(
                          children: [
                            Image.asset(
                              "assets/app/home_dw.png",
                              height: 25,
                              width: 25,
                            ),
                            Text('北京')
                          ],
                        ),
                      ),
                      SizedBox(width: 10),
                      GestureDetector(
                        onTap: () {
                          EmployerPageDialog.sort(context,(type){
                            utilRouter.back();
                            print('>]type=${type}');
                          });
                        },
                        child:   Container(
                          child: Image.asset(
                            "assets/app/home_px1.png",
                            height: 25,
                            width: 25,
                          ),
                        ),
                      ),
                      SizedBox(width: 10),
                      GestureDetector(
                        onTap: () {
                          print('按钮被点击了');
                          MyToast.show(context,'aaa');
                          EmployerPageDialog.dialog_workTypeSelect(context,(data){
                            print(">]拿到数据 data1=${data['list_gz']?.length}");
                            print(">]拿到数据 data2=${data['list_xz']?.length}");
                          });

                        },
                        child:    Container(
                          child: Image.asset(
                            "assets/app/home_sx.png",
                            height: 25,
                            width: 25,
                          ),
                        ),
                      ),
                      SizedBox(width: 10),

                    ],
                  ),
                ),
              ],
            ),
          ),
          Divider(height: 2, thickness: 1,color: myColors.c_D1D3D5),
          Expanded(
              child: IndexedStack(
                index: controller.page_index.value,
                sizing: StackFit.expand,
                children: [
                  MyListView(type: 0,page_index: controller.page_index.value,),
                  MyListView(type: 1,page_index: controller.page_index.value,),
                  // getListView(context,1),
                  // getListView(context,2)
                ],
              )

          ),
        ],
      ),
    ));
  }

  TextStyle getViewSelectTitle(int index) {
    if (index == controller.page_index.value) {
      return TextStyle(
        color: myColors.c_191919,
        fontSize: 20,
        fontWeight: FontWeight.bold,
      );
    }
    return TextStyle(
      color: myColors.c_191919,
      fontSize: 16,
      fontWeight: FontWeight.normal,
    );
  }
    Widget getView(int type){
    return Text("type${type}");
    }

}
